package com.xing.util;

import java.util.HashMap;

import android.app.ProgressDialog;
import android.content.Context;

public class HsdProgressDialog {


	private static  HashMap<String, Integer> hashMap;

	private static ProgressDialog progressDialog;
	
	public static void getProgressDialog(Context context) {
		try {
			if (progressDialog == null) {
				progressDialog = new ProgressDialog(context);
				progressDialog.setMessage("加载中");
			}
			progressDialog.show();
			if (hashMap == null)
				hashMap = new HashMap<String, Integer>();
			String key = context.getClass().getName();
			if (!hashMap.containsKey(key)) {
				hashMap.put(key, 1);
			} else {
				hashMap.put(key, hashMap.get(key) + 1);
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			MyLog.outLogDetail(e.getMessage());
			progressDialog.dismiss();
			progressDialog = null;
		}
	}
	
	public static void dismissProgressDialog(Context context){
		try {
			if (hashMap == null)
				hashMap = new HashMap<String, Integer>();
			String key = context.getClass().getName();
			if (hashMap.containsKey(key)) {
				hashMap.put(key, hashMap.get(key)-1);
				if (hashMap.get(key) == 0) {
					if (progressDialog != null) {
						progressDialog.dismiss();
						progressDialog = null;
						hashMap.clear();
					}
				}
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	
		
	}

}
